package com.example.service;

import com.example.dao.LogDao;
import com.example.entity.Log;
import com.example.entity.Params;
import com.example.exception.CustomException;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogService {

    @Resource
    LogDao logDao;

    public PageInfo<Log> findLog(Params params) {
        //开启分页查询
        PageHelper.startPage(params.getPageNum(), params.getPageSize());
        //接下来的查询会按照当前的分页设置自动进行查询
        List<Log> list = logDao.findLog(params);
        return PageInfo.of(list);
    }

    public void add(Log log) {
        if (log.getUsername().isEmpty()) {
            throw new CustomException("系统异常");
        }
        logDao.add(log);
    }

    public void del(Integer logId) {
        logDao.deleteById(logId);
    }
}
